package com.jumper.study.front.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jumper.study.common.api.CommonPageResult;
import com.jumper.study.common.api.CommonResult;
import com.jumper.study.common.util.AdminUtil;
import com.jumper.study.db.model.Account;
import com.jumper.study.front.dto.req.MyLessonSearchReq;
import com.jumper.study.front.dto.resp.LessonEbookResp;
import com.jumper.study.front.dto.resp.MyLessonChapterResp;
import com.jumper.study.front.dto.resp.MyLessonListItemResp;
import com.jumper.study.front.dto.vo.PageVO;
import com.jumper.study.front.service.StudentLessonService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;


@RestController("frontStudentLessonController")
@RequestMapping("/api/front/my/lessons")
public class StudentLessonController {
    
    @Autowired
    private AdminUtil adminUtil;

    @Autowired
    private StudentLessonService lessonService;

    /**
     * 我的课程列表查询
     * @param req
     * @return
     */
    @PostMapping("/")
    public CommonPageResult<List<MyLessonListItemResp>> lessons(@RequestBody MyLessonSearchReq req) {
        PageVO page = new PageVO(req.getPage(), req.getLimit());
        Account account = adminUtil.getAccount();
        req.setAccountId(account.getId());
        List<MyLessonListItemResp> resp = lessonService.pageSearchList(page, req);
        return CommonPageResult.restPage(page.getPage(), page.getPageSize(), page.getTotal(), resp);
    }

    /**
     * 我的课程章节列表
     * @param id
     * @return
     */
    @GetMapping("/{id}/chapters")
    public CommonResult<List<MyLessonChapterResp>> chapters(@PathVariable Long id) {
        Account account = adminUtil.getAccount();
        List<MyLessonChapterResp> resp = lessonService.chapters(id, account.getId());
        return CommonResult.success(resp);
    }
    
    /**
     * 我的课程课件列表
     * @param id
     * @return
     */
    @GetMapping("/{id}/ebooks")
    public CommonResult<List<LessonEbookResp>> ebooks(@PathVariable Long id) {
        Account account = adminUtil.getAccount();
        List<LessonEbookResp> resp = lessonService.ebooks(id, account.getId());
        return CommonResult.success(resp);
    }
    
}
